﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPageMcSigAdmin.master" AutoEventWireup="true" CodeFile="Client.aspx.cs" Inherits="Client" %>
<%@ Register assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.v12.2, Version=12.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView.Export" tagprefix="dx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">
    // <![CDATA[
    function OnCountryChanged(cmbCountry) {
        ASPxGridViewClientes.GetEditor("MUNICIPIO").PerformCallback(cmbCountry.GetValue().toString());
    }
    // ]]> 
    </script>
    <dx:ASPxGridView ID="ASPxGridViewClientes" runat="server" ClientInstanceName="ASPxGridViewClientes"
        AutoGenerateColumns="False" DataSourceID="SqlDataSourceClientes" 
        EnableTheming="True" KeyFieldName="ACT_ID" Theme="PlasticBlue" 
        oncelleditorinitialize="ASPxGridViewClientes_CellEditorInitialize" 
        onrowinserting="ASPxGridViewClientes_RowInserting">
        <Columns>
            <dx:GridViewCommandColumn VisibleIndex="0" Caption="Opciones">
                <ClearFilterButton Visible="True" />
                <EditButton Visible="True">
                </EditButton>
                <NewButton Visible="True">
                </NewButton>
                <DeleteButton Visible="True">
                </DeleteButton>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataTextColumn FieldName="ACT_ID" ReadOnly="True" VisibleIndex="1" 
                Caption="Id">
                <EditFormSettings Visible="False" />
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="ACT_CONTACTO" VisibleIndex="3" 
                Caption="Contacto">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Caption="Cliente" FieldName="ACT_NOMBRE" 
                ShowInCustomizationForm="True" VisibleIndex="2">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="ACT_TELEFONO" VisibleIndex="5" 
                Caption="Telefono">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="ACT_DIRECCION" VisibleIndex="6" 
                Caption="Dirección">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataComboBoxColumn FieldName="DEPARTAMENTO" VisibleIndex="11">
                <PropertiesComboBox TextField="ZON_NOMBRE" ValueField="ZON_ID" EnableSynchronization="False"
                IncrementalFilteringMode="StartsWith" DataSourceID="Departamentos">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { OnCountryChanged(s); }">
                    </ClientSideEvents>
                </PropertiesComboBox>
                <Settings AllowAutoFilter="True" AllowAutoFilterTextInputTimer="True" 
                    FilterMode="DisplayText" />
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataTextColumn FieldName="ACT_NIT" VisibleIndex="13" 
                Caption="Nit">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataComboBoxColumn FieldName="MUNICIPIO" VisibleIndex="12">
                <PropertiesComboBox EnableSynchronization="False" TextField="ZON_NOMBRE" ValueField="ZON_ID" IncrementalFilteringMode="StartsWith"
                                        DropDownStyle="DropDown">
                </PropertiesComboBox>
                <Settings FilterMode="DisplayText" />
            </dx:GridViewDataComboBoxColumn>
        </Columns>
        <SettingsBehavior ConfirmDelete="True" />
        <Settings ShowFilterRow="True" ShowGroupPanel="True" ShowFilterRowMenu="True" />
    </dx:ASPxGridView>
    <asp:SqlDataSource ID="SqlDataSourceClientes" runat="server" 
        ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>" 
        DeleteCommand="DELETE FROM [AUT_CLIENT] WHERE [ACT_ID] = @ACT_ID" 
        InsertCommand="INSERT INTO [AUT_CLIENT] ([ACT_NOMBRE], [ACT_NIT], [ACT_DIRECCION], [ACT_TELEFONO], [ACT_CONTACTO], [ZON_ID]) VALUES (@ACT_NOMBRE, @ACT_NIT, @ACT_DIRECCION, @ACT_TELEFONO, @ACT_CONTACTO, @MUNICIPIO)" 
        SelectCommand="SELECT        dbo.AUT_CLIENT.ACT_ID, dbo.AUT_CLIENT.ACT_NOMBRE, dbo.AUT_CLIENT.ACT_NIT, dbo.AUT_CLIENT.ACT_DIRECCION, dbo.AUT_CLIENT.ACT_TELEFONO, 
                         dbo.AUT_CLIENT.ACT_CONTACTO, dbo.AUT_CLIENT.ZON_ID, dbo.BAS_ZONAS_GEOGRAFICAS.ZON_NOMBRE AS MUNICIPIO, 
                         BAS_ZONAS_GEOGRAFICAS_1.ZON_NOMBRE AS DEPARTAMENTO
FROM            dbo.AUT_CLIENT INNER JOIN
                         dbo.BAS_ZONAS_GEOGRAFICAS ON dbo.AUT_CLIENT.ZON_ID = dbo.BAS_ZONAS_GEOGRAFICAS.ZON_ID INNER JOIN
                         dbo.BAS_ZONAS_GEOGRAFICAS AS BAS_ZONAS_GEOGRAFICAS_1 ON 
                         dbo.BAS_ZONAS_GEOGRAFICAS.ZON_PADRE_ID = BAS_ZONAS_GEOGRAFICAS_1.ZON_ID" 
        
        UpdateCommand="UPDATE [AUT_CLIENT] SET [ACT_NOMBRE] = @ACT_NOMBRE, [ACT_NIT] = @ACT_NIT, [ACT_DIRECCION] = @ACT_DIRECCION, [ACT_TELEFONO] = @ACT_TELEFONO, [ACT_CONTACTO] = @ACT_CONTACTO, [ZON_ID] = @MUNICIPIO WHERE [ACT_ID] = @ACT_ID">
        <DeleteParameters>
            <asp:Parameter Name="ACT_ID" Type="Decimal" />
        </DeleteParameters>
        <InsertParameters>
        <asp:Parameter Name="ACT_NOMBRE" Type="String" />
            <asp:Parameter Name="ACT_NIT" Type="String" />
            <asp:Parameter Name="ACT_DIRECCION" Type="String" />
            <asp:Parameter Name="ACT_TELEFONO" Type="String" />
            <asp:Parameter Name="ACT_CONTACTO" Type="String" />
            <asp:Parameter Name="MUNICIPIO" Type="String" />
        </InsertParameters>
        <UpdateParameters>
        <asp:Parameter Name="ACT_NOMBRE" Type="String" />
            <asp:Parameter Name="ACT_NIT" Type="String" />
            <asp:Parameter Name="ACT_DIRECCION" Type="String" />
            <asp:Parameter Name="ACT_TELEFONO" Type="String" />
            <asp:Parameter Name="ACT_CONTACTO" Type="String" />
            <asp:Parameter Name="ACT_ID" Type="Decimal" />
            <asp:Parameter Name="MUNICIPIO" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
   

    <dx:ASPxButton ID="ASPxButton1" runat="server" Text="Exportar Clientes" 
        Theme="PlasticBlue" onclick="ASPxButton1_Click">
    </dx:ASPxButton>
   

    <asp:SqlDataSource ID="Departamentos" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"
                            SelectCommand="SELECT ZON_ID, ZON_NOMBRE FROM BAS_ZONAS_GEOGRAFICAS WHERE (ZON_PADRE_ID IS NULL)">
                        </asp:SqlDataSource>


    <dx:ASPxGridViewExporter ID="ASPxGridViewExporterClientes" runat="server" 
        GridViewID="ASPxGridViewClientes">
    </dx:ASPxGridViewExporter>
   

                        <asp:SqlDataSource ID="Municipios" runat="server" ConnectionString="<%$ ConnectionStrings:MCSIGConnectionString %>"    
                            SelectCommand="SELECT ZON_ID, ZON_NOMBRE, ZON_PADRE_ID, ZON_POBLACION FROM BAS_ZONAS_GEOGRAFICAS WHERE (ZON_PADRE_ID = @ZON_ID)">
                            <SelectParameters>
                                <asp:Parameter Name="ZON_ID" DbType="String" />
                            </SelectParameters>
                        </asp:SqlDataSource>


    </asp:Content>

